/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Pert12;

import java.util.Scanner;

/**
 *
 * @author admin
 */
public class MainToko {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        String jawab;
        int pilih,i=0;
        Scanner sc=new Scanner(System.in);
        Toko barang[]=new Toko[10];
        do            
        {
            System.out.println("Pilih data yang akan dimasukkan :");
            System.out.println("1. Pakaian");
            System.out.println("2. Makanan");
            System.out.println("3. Obat-obatan");
            pilih=sc.nextInt();
            if (pilih== 1)
            {
                barang[i]=new Pakaian();
                System.out.print("\nMasukkan kode barang ");
                barang[i].setKode(sc.next());
                System.out.print("\nMasukkan nama barang ");
                barang[i].setNama(sc.next());
                System.out.print("\nMasukkan harga barang ");
                barang[i].setHarga(sc.nextDouble());
                System.out.print("\nMasukkan ukuran pakaian ");
                ((Pakaian)barang[i]).setUkuran(sc.next());
                System.out.print("\nMasukkan warna pakaian ");
                ((Pakaian)barang[i]).setWarna(sc.next());
                System.out.print("\nMasukkan discount pakaian ");
                ((Pakaian)barang[i]).setDiscount(sc.nextInt());
            }else if (pilih==2)
            {                
                barang[i]=new Makanan();
                System.out.print("\nMasukkan kode barang ");
                barang[i].setKode(sc.next());
                System.out.print("\nMasukkan nama barang ");
                barang[i].setNama(sc.next());
                System.out.print("\nMasukkan harga barang ");
                barang[i].setHarga(sc.nextDouble());
                System.out.print("\nMasukkan kadaluarsa makanan ");
                ((Makanan)barang[i]).setKadaluarsa(sc.next());
                System.out.print("\nMasukkan asal makanan ");
                ((Makanan)barang[i]).setAsal(sc.next());
                
            }else if (pilih==3)
            {
                barang[i]=new Obat();
                System.out.print("\nMasukkan kode barang ");
                barang[i].setKode(sc.next());
                System.out.print("\nMasukkan nama barang ");
                barang[i].setNama(sc.next());
                System.out.print("\nMasukkan harga barang ");
                barang[i].setHarga(sc.nextDouble());
                System.out.print("\nMasukkan kadaluarsa obat ");
                ((Obat)barang[i]).setKadaluarsa(sc.next());
                System.out.print("\nMasukkan dosis obat ");
                ((Obat)barang[i]).setDosis(sc.next());
                
            }else{
                System.out.println("Anda salah memasukkan pilihan");}
            
            System.out.print("Apakah akan memasukkan data lagi ?"); 
            jawab=sc.next();
            i++;
        }while (jawab.equals("y") || jawab.equals("Y"));
       
        System.out.println("  No. Kode        Nama     Jenis   Kadaluwarsa   Harga   Discount");
        for(int j=0;j<i;j++)
        {
            System.out.print(String.format("%4s", j+1));
            System.out.print(String.format("%6s", barang[j].getKode()));
            System.out.print(String.format("%13s", barang[j].getNama()));
            if (barang[j] instanceof Pakaian)
            {
                System.out.print(String.format("%10s", "Pakaian"));
                System.out.print(String.format("%12s", ""));
                System.out.print(String.format("%12s", ((Pakaian)barang[j]).getHarga()));
                System.out.print(String.format("%5s", ((Pakaian)barang[j]).getDiscount()));
            }
            else if (barang[j] instanceof Makanan)
            {
                System.out.print(String.format("%10s", "Makanan"));
                System.out.print(String.format("%12s", ((Makanan)barang[j]).getKadaluarsa()));
                System.out.print(String.format("%12s", barang[j].getHarga()));
                System.out.print(String.format("%5s", ""));
            }
            else if (barang[j] instanceof Obat)                
            {
                System.out.print(String.format("%10s", "Obat"));
                System.out.print(String.format("%12s", ((Obat)barang[j]).getKadaluarsa()));
                System.out.print(String.format("%12s", barang[j].getHarga()));
                System.out.print(String.format("%5s", ""));
            }
            System.out.println("");
        }
    }
}
